FIND_PACKAGE(PkgConfig)
pkg_search_module(LUA REQUIRED lua lua5.1)
IF (NOT LUA_FOUND)
MESSAGE(FATAL_ERROR "Lua could not be found!\n"
	"Lua is required for compiling lua interface!")
ENDIF ()
SET(LUA_EXECUTABLE lua)
UNSET(TARGET_SWIGFLAGS)

include(ShogunInterfaces)
include_directories(${LUA_INCLUDE_DIRS})

SET(INTERFACE_LUA_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
GENERATE_INTERFACE_TARGET(lua ${CMAKE_CURRENT_SOURCE_DIR} "${LUA_LDFLAGS}")

IF (NOT LIB_INSTALL_DIR)
	SET(LIB_INSTALL_DIR lib)
ENDIF()

STRING(REGEX REPLACE "([0-9]*.[0-9]*).[0-9]*" "${LIB_INSTALL_DIR}/lua/\\1" LUA_EXTENSION_DIR ${LUA_VERSION})

INSTALL(TARGETS interface_lua
	LIBRARY DESTINATION ${LUA_EXTENSION_DIR}
	COMPONENT lua)
